package cn.ldf.keepaccounts.service.impl;

import cn.ldf.keepaccounts.entity.dto.AvatarFileDTO;
import cn.ldf.keepaccounts.exception.ServerException;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.ldf.keepaccounts.entity.pojo.UserFile;
import cn.ldf.keepaccounts.service.UserFileService;
import cn.ldf.keepaccounts.dao.UserFileDao;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

/**
* @author ldf
* @description 针对表【user_file(用户文件表)】的数据库操作Service实现
* @createDate 2025-03-01 16:23:05
*/
@Service
public class UserFileServiceImpl extends ServiceImpl<UserFileDao, UserFile>
    implements UserFileService{

    @Override
    public Boolean uploadPaymentCode(AvatarFileDTO avatarFileDTO) {
        String avatarBase64 = avatarFileDTO.getAvatarBase64();
        String openId = avatarFileDTO.getOpenId();
        boolean isExists = this.lambdaQuery().eq(UserFile::getOpenId, openId).exists();
        byte[] bytes = avatarBase64.getBytes();
        UserFile userFile = new UserFile();
        userFile.setOpenId(openId);
        userFile.setPaymentCode(bytes);
        return isExists?this.updateByOpenId(userFile):this.save(userFile);
    }

    public Boolean updateByOpenId(UserFile userFile){
        return this.lambdaUpdate().eq(UserFile::getOpenId,userFile.getOpenId()).update(userFile);
    }

    @Override
    public List<UserFile> getListPaymentCodeByOpenIds(List<String> openIds) {
        return this.lambdaQuery().in(UserFile::getOpenId,openIds).list();
    }
}




